﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.ProductionScheduling
{
    public class SchedulingDisplayUpdateHandler : IRequestHandler<SchedulingDisplayUpdateCommond, ResultsDTO<givebirth>>
    {


        private readonly IBateRepository<givebirth> _givebirth;

        public SchedulingDisplayUpdateHandler(IBateRepository<givebirth> givebirth)
        {
            _givebirth = givebirth;
        }

        public async Task<ResultsDTO<givebirth>> Handle(SchedulingDisplayUpdateCommond request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new ResultsDTO<givebirth>() { Code = 0 };
                var str = "update givebirth SET Productionname='"+request.Productionname+"',Productionnum='"+request.Productionnum+"',StartTime='"+request.StartTime+"',ProductionTime='"+request.ProductionTime+"',FinshTime='"+request.FinshTime+"',QuantityProduced='"+request.QuantityProduced+"' WHERE Productionid="+request.Productionid+"";
                var Empty = new givebirth();
                DapperHelper dapperHelper = new DapperHelper();
                var hk = await _givebirth.Add(str, Empty, dapperHelper.MangoMesWrite);
                if (hk != null)
                {
                    list.Code = 1;
                    list.Message = "生产任务修改成功";
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
           

        }
    }
}
